<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcCms.Web.ViewModels.BackOfficeModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    MvcCms -
    <%=ViewData["PageTitle"]%>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="contentpage-outerdiv">
        <h2>
            <%=ViewData["PageTitle"]%></h2>
        <div class="contentpage-outerdiv">
            <h2>
                <%=ViewData["PageTitle"]%></h2>
            <span class="field-validation-error">
                <%=ViewData["message"].ToString()%></span>
            <% using (Html.BeginForm("ImageManager", "BackOffice", FormMethod.Post, new { id = "form1", enctype = "multipart/form-data" }))
               {%>
            <div>
                <div>
                    Upload Images</div>
                <div>
                    <table>
                        <tr>
                            <td>
                                Zip File:
                            </td>
                            <td>
                                <input type="file" id="file1" name="filezip" />
                            </td>
                            <td rowspan="3">
                                <input type="submit" id="Submit1" value="Upload" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Single File:
                            </td>
                            <td>
                                <input type="file" id="File2" name="singlefile" />
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <div style="height: 389px; overflow: scroll">
                <fieldset>
                    <legend>
                        <%=Html.Encode(Model._Files.Count().ToString())%>
                        Images Detected</legend>
                    <table border="1">
                        <%
                            int i = 0;
                            foreach (var file in Model._Files)
                            {
                                if ((i % 4) == 0)
                                {%>
                        <tr>
                            <td>
                                <%}
                                else
                                {%>
                                <td>
                                    <%}%>
                                    <table id="cell-<%=i %>">
                                        <tr>
                                            <td>
                                                <a href="/Uploadedimages/<%=Model._Portal.Name.ToUrlFormat() %>/<%=file.Name%>">
                                                    <img border="0" alt="<%=Html.Encode(file.Name)%>" src="/Uploadedimages/<%=Model._Portal.Name.ToUrlFormat() %>/thumbs/<%=file.Name%>" />
                                                </a>
                                            </td>
                                            <td>
                                                <%=Html.Encode(file.LastWriteTime.ToString("d"))%>
                                            </td>
                                            <td>
                                                <a onclick="DeleteImage('<%=file.Name %>', <%=i %>)" href="javascript:void(0)">Del</a>
                                            </td>
                                        </tr>
                                    </table>
                                    <%
                                        if ((i % 2) != 0)
                                        {%>
                                </td>
                        </tr>
                        <%}
                                        else
                                        {%>
                        </td>
                        <%}

                                        i += 1;
                            } %>
                    </table>
                </fieldset>
            </div>
            <%} %>
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeaderContent" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ScriptContent" runat="server">

    <script src="/Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        function DeleteImage(imageToDelete, cellnum) {
            $.post(
            "/backofficeajax/deleteimage/0/" + imageToDelete,
            function(data) {
                var objdata = JSON.parse(data);
                if (objdata.error) {
                    alert(objdata.error);
                }
                else {
                    if (objdata.result == "success") {
                        RemoveFileContainer(cellnum);
                    }
                    else {
                        alert("There was a problem removing the image.");
                    }
                }
            },
            "json"
            );
        }

        function RemoveFileContainer(rownum) {
            $("#cell-" + rownum).fadeOut("normal", function() {
                $(this).remove();
            });
        }
    </script>

</asp:Content>
